<script setup lang="ts">

import CourseTableTemplate from "../../components/CourseTableTemplate.vue";
import {onMounted, ref} from "vue";
import {getCourseSelectionList} from "../../apis/CourseSelectionApi.ts";
import {useStore} from "../../store";
import {ElMessage} from "element-plus";
import {getCourseListByDepartmentId} from "../../apis/CourseAssignmentApi.ts";
import {getCourseById} from "../../apis/CourseApi.ts";
// {
//   xq: 4,
//       title: '形势与政治',
//     class: 'sport',
//     content: '1-2节' + '/' + '社会学1班' + '/' + '5教-402室',
//     start: 1,
//     end: 2
// }
const store = useStore()
const data = ref<{xq: number;title: string;content: string;start: number;end: number; }>([])
const getData = async () => {
  //获取学生课表
  const res = await getCourseSelectionList(store.studentInfo.departmentId,undefined,store.studentInfo.id)
  console.log('获取学生课表',res)
  if (res.code === 200) {
    for (let i = 0; i < res.data.length; i++) {
      //查询课程信息
      const courseRes = await getCourseById(res.data[i].courseId)
      data.value.push({
        xq: courseRes.data.xq,
        title: courseRes.data.name,
        content: courseRes.data.teacher + '/' + courseRes.data.description,
        start: courseRes.data.start,
        end: courseRes.data.end
      })
    }
  }else{
    ElMessage.error(res.msg)
  }
}

onMounted(async () => {
  await getData()
})
</script>

<template>
<CourseTableTemplate
    :afternoon-length="5"
    :events="data"
    :length="12"/>
</template>

<style scoped>

</style>